package com.ruoyi.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.business.VO.AcLeaseInfoListVO;
import com.ruoyi.framework.web.domain.server.Sys;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.AcLeaseInfo;
import com.ruoyi.business.service.IAcLeaseInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 租赁台账管理Controller
 *
 * @author ruoyi
 * @date 2025-01-22
 */
@RestController
@RequestMapping("/business/leaseInfo")
public class AcLeaseInfoController extends BaseController
{
    @Autowired
    private IAcLeaseInfoService acLeaseInfoService;

    /**
     * 查询租赁台账管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:leaseInfo:list')")
    @GetMapping("/list")
    @ApiOperation("查询租赁台账管理列表")
    public TableDataInfo list(AcLeaseInfo acLeaseInfo)
    {
        startPage();
        List<AcLeaseInfo> list = acLeaseInfoService.selectAcLeaseInfoListReal(acLeaseInfo);
        return getDataTable(list);
    }


    /**
     * 查询租赁台账管理详情
     */
    @PreAuthorize("@ss.hasPermi('business:leaseInfo:list')")
    @GetMapping("/listDetail")
    @ApiOperation("查询租赁台账管理列表")
    public AjaxResult  listDetail (AcLeaseInfo acLeaseInfo)
    {
        AcLeaseInfo result = new AcLeaseInfo();
        result  = acLeaseInfoService.selectAcLeaseInfoListDetail(acLeaseInfo);
           return success(result);
    }


    /**
     * 导出租赁台账管理列表
     */
//    @PreAuthorize("@ss.hasPermi('business:leaseInfo:export')")
    @Log(title = "租赁台账管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AcLeaseInfo acLeaseInfo)
    {
        List<AcLeaseInfo> list = acLeaseInfoService.selectAcLeaseInfoList(acLeaseInfo);
        ExcelUtil<AcLeaseInfo> util = new ExcelUtil<AcLeaseInfo>(AcLeaseInfo.class);
        util.exportExcel(response, list, "租赁台账管理数据");
    }

    /**
     * 获取租赁台账管理详细信息
     */
//    @PreAuthorize("@ss.hasPermi('business:leaseInfo:query')")
    @GetMapping(value = "/{leaseId}")
    @ApiOperation("获取租赁台账管理详细信息")
    public AjaxResult getInfo(@PathVariable("leaseId") Long leaseId)
    {
        AcLeaseInfo acLeaseInfo = new AcLeaseInfo();
        acLeaseInfo.setLeaseId(leaseId);
        return success(acLeaseInfoService.selectAcLeaseInfoListDetail(acLeaseInfo));
    }

    /**
     * 新增租赁台账管理
     */
//    @PreAuthorize("@ss.hasPermi('business:leaseInfo:add')")
    @Log(title = "租赁台账管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AcLeaseInfo acLeaseInfo)
    {
        int insertIsOk = acLeaseInfoService.insertAcLeaseInfo(acLeaseInfo);
        if(0 == insertIsOk) {
            return AjaxResult.error("资产状态不可租赁！");
        } else {
            return toAjax(insertIsOk);
        }
    }

    /**
     * 修改租赁台账管理
     */
//    @PreAuthorize("@ss.hasPermi('business:leaseInfo:edit')")
    @Log(title = "租赁台账管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AcLeaseInfo acLeaseInfo)
    {
        return toAjax(acLeaseInfoService.updateAcLeaseInfo(acLeaseInfo));
    }

    /**
     * 删除租赁台账管理
     */
//    @PreAuthorize("@ss.hasPermi('business:leaseInfo:remove')")
    @Log(title = "租赁台账管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{leaseIds}")
    public AjaxResult remove(@PathVariable Long[] leaseIds)
    {
        int removeOk = acLeaseInfoService.deleteAcLeaseInfoByLeaseIds(leaseIds);
        if(0 == removeOk) {
            return AjaxResult.error("租赁未到期！");
        } else {
            return AjaxResult.success();
        }
    }

    // ****************************************************************************
//    @ApiOperation("查询租赁台账管理列表")
//    @GetMapping("/selectAcLeaseInfoList")
//    public TableDataInfo selectAcLeaseInfoList(AcLeaseInfo acLeaseInfo) {
//        startPage();
//        List<AcLeaseInfoListVO> list = acLeaseInfoService.getAcLeaseInfoList(acLeaseInfo);
//        return getDataTable(list);
//    }
//
//    @ApiOperation("获取租赁台账管理详细信息")
//    @GetMapping("/getAcLeaseInfoByLeaseId/{leaseId}")
//    public AjaxResult getAcLeaseInfoByLeaseId(@PathVariable("leaseId") Long leaseId) {
//        return success(acLeaseInfoService.getAcLeaseInfoByLeaseId(leaseId));
//    }


    /**
     * 手动更新租赁台账管理
     * **/
    @GetMapping("/updateAcLeaseByCurrentDate")
    public AjaxResult updateAcLeaseByCurrentDate() {
        acLeaseInfoService.updateAcLeaseByCurrentDate();
        return success();
    }
}
